home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Complete Linux
/
Complete Linux.iso
/
xwindows
/
demos
/
xfract_1.z
/
xfract_1
/
xfractint-1.06
/
targa.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-28
|
20KB
|
776 lines
/** targa.c **/
#ifdef __TURBOC__
# pragma warn -par
#endif
#define TARGA_DATA
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef XFRACT
#include <conio.h>
#endif
#include "targa.h"
#include "fractint.h"
#include "prototyp.h"
/************* ****************/
extern char far *mapdacbox;
/************* ****************/
void WriteTGA( int x, int y, int index );
int ReadTGA ( int x, int y );
void EndTGA ( void );
void StartTGA( void );
void ReopenTGA( void );
/************* ****************/
static unsigned _fastcall near Row16Calculate(unsigned,unsigned);
static void _fastcall near PutPix16(int,int,int);
static unsigned _fastcall near GetPix16(int,int);
static unsigned _fastcall near Row32Calculate(unsigned,unsigned);
static void _fastcall near PutPix32(int,int,int);
static unsigned _fastcall near GetPix32(int,int);
static void _fastcall near DoFirstPixel(int,int,int);
static void _fastcall fatalerror(char far *);
static int GetLine(int);
static void _fastcall near SetDispReg(int,int);
static int VWait(void);
static void _fastcall SetVBorder(int,int);
static void _fastcall SetBorderColor(long);
static void _fastcall SetVertShift(int);
static void _fastcall SetInterlace(int);
static void _fastcall SetBlndReg(int);
static void _fastcall SetRGBorCV(int);
static void _fastcall SetVCRorCamera(int);
static void _fastcall SetMask(int);
static void _fastcall SetBlndReg(int);
static void _fastcall SetContrast(int);
static void _fastcall SetHue(int);
static void _fastcall SetSaturation(int);
static void _fastcall SetHBorder(int,int);
static void SetFixedRegisters(void);
static void _fastcall VCenterDisplay(int);
static void _fastcall SetOverscan(int);
static void _fastcall near TSetMode(int);
static int GraphInit(void);
static void GraphEnd(void);
/************* ****************/
int xorTARGA;
unsigned far *tga16 = NULL; /* [256] */
long far *tga32; /* [256] */
static int last = 0;
/************* ****************/
extern int sxdots,sydots; /* # of dots on the physical screen */
static int initialized;
/************* ****************/
static void (near _fastcall *DoPixel) ( int x, int y, int index );
static void (near _fastcall *PutPixel)( int x, int y, int index );
static unsigned (near _fastcall *GetPixel)( int x, int y );
/**************************************************************************/
#ifdef __BORLANDC__
#if(__BORLANDC__ > 2)
#pragma warn -eff
#endif
#endif
static unsigned _fastcall near Row16Calculate( unsigned line, unsigned x1 )
{
outp( DESTREG, (line >> 5) );
return( ((line & 31) << 10) | (x1 << 1) ); /* calc the pixel offset */
}
/**************************************************************************/
static void _fastcall near PutPix16( int x, int y, int index )
{
unsigned far * ip;
/**************/
ip = MK_FP( MEMSEG, Row16Calculate( y, x ) );
if( ! xorTARGA )
*ip = tga16[index];
else
*ip = *ip ^ 0x7fff;
}
/**************************************************************************/
static unsigned _fastcall near GetPix16( int x, int y )
{
register unsigned pixel, index;
unsigned far * ip;
/**************/
ip = MK_FP( MEMSEG, Row16Calculate( y, x ) );
pixel = *ip & 0x7FFF;
if( pixel == tga16[last] ) return( last );
for( index = 0; index < 256; index++ )
if( pixel == tga16[index] ) {
last = index;
return( index );
}
return( 0 );
}
/**************************************************************************/
static unsigned _fastcall near Row32Calculate( unsigned line, unsigned x1 )
{
outp( DESTREG, (line >> 4) );
return ( ((line & 15) << 11) | (x1 << 2) ); /* calc the pixel offset */
}
/**************************************************************************/
static void _fastcall near PutPix32( int x, int y, int index )
{
long far * lp;
lp = MK_FP( MEMSEG, Row32Calculate( y, x ) );
if( ! xorTARGA )
*lp = tga32[index];
else
*lp = *lp ^ 0x00FFFFFF;
}
/**************************************************************************/
static unsigned _fastcall near GetPix32( int x, int y )
{
register int index;
long pixel;
long far * lp;
lp = MK_FP( MEMSEG, Row32Calculate( y, x ) );
pixel = *lp & 0x00FFFFFF;
if( pixel == tga32[last] ) return( last );
for( index = 0; index < 256; index++ )
if( pixel == tga32[index] ) {
last = index;
return( index );
}
return( 0 );
}
/**************************************************************************/
static void _fastcall near DoFirstPixel( int x, int y, int index )
{
int cnt;
TSetMode( targa.mode | 1 );
for( cnt = 0; cnt < targa.MaxBanks; cnt += 2 ) { /* erase */
outp( DESTREG, cnt );
outp( SRCREG, cnt + 1 );
erasesegment(targa.memloc,0); /** general.asm **/
}
TSetMode( targa.mode & 0xFFFE );
PutPixel = DoPixel;
(*PutPixel)( x, y, index );
}
#ifdef __BORLANDC__
#if(__BORLANDC__ > 2)
#pragma warn +eff
#endif
#endif
/***************************************************************************/
void WriteTGA( int x, int y, int index )
{
OUTPORTB(MODEREG, targa.mode |= 1 ); /* TSetMode inline for speed */
(*PutPixel)( x, sydots-y, index&0xFF ); /* fix origin to match EGA/VGA */
OUTPORTB(MODEREG, targa.mode &= 0xFFFE );
}
/***************************************************************************/
int ReadTGA( int x, int y )
{
int val;
OUTPORTB(MODEREG, targa.mode |= 1 ); /* TSetMode inline for speed */
val = (*GetPixel)( x, sydots-y );
OUTPORTB(MODEREG, targa.mode &= 0xFFFE );
return( val );
}
/***************************************************************************/
void EndTGA( void )
{
if( initialized ) {
GraphEnd();
initialized = 0;
}
}
/***************************************************************************/
void StartTGA()
{
int i;
static char far couldntfind[]={"Could not find Targa card"};
static char far noenvvar[]={"TARGA enviroment variable missing"};
static char far insuffmem[]={"Insufficient memory for Targa"};
/****************/
if( initialized ) return;
initialized = 1;
/****************/
/* note that video.asm has already set the regualar video adapter */
/* to text mode (ax in Targa table entries is 3); */
/* that's necessary because TARGA can live at 0xA000, we DO NOT */
/* want to have an EGA/VGA in graphics mode!! */
ReopenTGA(); /* clear text screen and display message */
/****************/
/*** look for and activate card ***/
if ((i = GraphInit()))
fatalerror((i == -1) ? couldntfind : noenvvar);
VCenterDisplay( sydots + 1 );
if (tga16 == NULL)
if ( (tga16 = (unsigned far *)farmemalloc(512L)) == NULL
|| (tga32 = (long far *)farmemalloc(1024L)) == NULL)
fatalerror(insuffmem);
SetTgaColors();
if( targa.boardType == 16 ) {
GetPixel = GetPix16;
DoPixel = PutPix16;
}
else {
GetPixel = GetPix32;
DoPixel = PutPix32;
}
PutPixel = DoFirstPixel; /* on first pixel --> erase */
if( sydots == 482 ) SetOverscan( 1 );
TSetMode( targa.mode & 0xFFFE );
/****************/
if (mapdacbox == NULL && SetColorPaletteName("default") != 0)
exit( 1 ); /* stopmsg has already been issued */
}
void ReopenTGA()
{
static char far runningontarga[]={"Running On TrueVision TARGA Card"};
helptitle();
putstring(2,20,7,runningontarga);
movecursor(6,0); /* in case of brutal exit */
}
static void _fastcall fatalerror(char far *msg)
{
static char far abortmsg[]={"...aborting!"};
putstring(4,20,15,msg);
putstring(5,20,15,abortmsg);
movecursor(8,0);
exit(1);
}
/*** the rest of this module used to be separate, in tgasubs.c, ***/
/*** has now been merged into a single source ***/
/*******************************************************************/
static void _fastcall VCenterDisplay( int nLines )
{
int lines;
int top, bottom;
long color;
lines = nLines >> 1; /* half value of last line 0..x */
top = 140 - (lines >> 1);
bottom = top + lines;
SetVBorder( top, bottom );
SetVertShift( 255 - lines ); /* skip lines we're not using */
if( targa.boardType == 16 )
color = (12 << 10) | (12 << 5) | 12;
else
color = ((long)80 << 16) | (80 << 8) | 80;
SetBorderColor( color );
}
/*****************************************************************/
static vo